<?php
/**
 * appRain v 0.1.x
 *
 * LICENSE
 *
 * This source file is subject to the MIT license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.opensource.org/licenses/mit-license.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@apprain.com so we can send you a copy immediately.
 *
 * @copyright  Copyright (c) 2010 appRain, Team. (http://www.apprain.com)
 * @license    http://www.opensource.org/licenses/mit-license.php MIT license
 *
 * HELP
 *
 * Official Website
 * http://www.apprain.com/
 *
 * Download Link
 * http://www.apprain.com/download
 *
 * Documents Link
 * http ://www.apprain.com/docs
 */
 ?>

<?php if( $action == 'update' ||  $action == 'add' ): ?>

<?php
    $adminlist = isset($this->data["Admin"]) ? $this->data["Admin"] : $adminlist;
    $adminlist['id'] = isset( $adminlist['id'] ) ? $adminlist['id'] : "";
    $adminlist['f_name'] = isset( $adminlist['f_name'] ) ? $adminlist['f_name'] : "";
    $adminlist['l_name'] = isset( $adminlist['l_name'] ) ? $adminlist['l_name'] : "";
    $adminlist['username'] = isset( $adminlist['username'] ) ? $adminlist['username'] : "";
    $adminlist['password'] = isset( $adminlist['password'] ) ? $adminlist['password'] : "";
    $adminlist['cpassword'] = isset( $adminlist['cpassword'] ) ? $adminlist['cpassword'] : $adminlist['password'];
    $adminlist['email'] = isset( $adminlist['email'] ) ? $adminlist['email'] : "";
    $adminlist['acl'] = isset( $adminlist['acl'] ) ? $adminlist['acl'] : "";
    $adminlist['description'] = isset( $adminlist['description'] ) ? $adminlist['description'] : "";
    $adminlist['status'] = isset( $adminlist['status'] ) ? $adminlist['status'] : "";
    $adminlist['type'] = isset( $adminlist['type'] ) ? $adminlist['type'] : "Normal";
?>

<?php
    /*
     * Set data validation fields
     */
    $validation_map = array(
                             "f_name" => "NULL",
                             "l_name" => "NULL"
                            );

    if(  $action == 'add'  )
    {
        $validation_map['username'] = 'NULL';
        $validation_map['email']    = 'EMAIL';
        $validation_map['password|cpassword'] = 'MATCH';
    }

    /*
     * Calling validation
     */
    echo App::Load("Helper/Javascript")->validation_map(array('_errBg'=>ERROR_BACKGROUND,'_dflBg'=>"#CECECE",'_autoSubmit'=>'true','_errToolTips'=>'false','_errorMark'=>'inline'));?>

<form method="post" action="<?php echo $this->baseUrl("/admin/manage/$action/" . $adminlist['id']); ?>" style="background-color:#FFF">
	<div class="box box-left box-padding box-left-tabs">
		<div class="title"><h5>Personal Information</h5></div>
		<div id="box-left-forms">
			<div class="form">
				<div class="fields">
					<div class="field">
						<div class="label">
							<label for="input">First Name:</label>
						</div>
						<div class="input">
							<?php echo App::load("Helper/Html")->inputTag("data[Admin][f_name]",$adminlist['f_name'],array("id"=>"f_name","class"=>"large check_notempty","longdesc"=>"Please enter  first name"));?>
						</div>
					</div>
					<div class="field">
						<div class="label">
							<label for="l_name">Last Name:</label>
						</div>
						<div class="input">
							<?php echo App::load("Helper/Html")->inputTag("data[Admin][l_name]",$adminlist['l_name'],array("id"=>"l_name","class"=>"large check_notempty","longdesc"=>"Please enter last name"));?>
						</div>
					</div>
					<div class="field">
						<div class="label">
							<label for="email">Email:</label>
						</div>
						<div class="input">
							<?php echo App::load("Helper/Html")->inputTag("data[Admin][email]",$adminlist['email'],array("id"=>"email","class"=>"large check_email","longdesc"=>"Please enter email address"));?>
						</div>
					</div>
					<?php if($action == 'add'):?>
					<div class="field">
						<div class="label">
							<label for="username">Username:</label>
						</div>
						<div class="input">
							<?php echo App::load("Helper/Html")->inputTag("data[Admin][username]",$adminlist['username'],array("id"=>"username","class"=>"large check_notempty","longdesc"=>"Please enter a valid user name"));?>
						</div>
					</div>
					<div class="field">
						<div class="label">
							<label for="password">Password:</label>
						</div>
						<div class="input">
							<?php echo App::load("Helper/Html")->passwordTag("data[Admin][password]",'',array("id"=>"password","class"=>"large check_notempty","longdesc"=>"Please enter with combination of A-Za-z0-9"));?>
						</div>
					</div>
					<?php endif;?>
					<div class="field">
						<div class="label">
							<label for="status">Status:</label>
						</div>
						<div class="input">
							<?php echo App::load("Helper/Html")->selectTag("data[Admin][status]",array("Active"=>"Active","Pending"=>"Pending"),$adminlist['status'],array('id'=>'status'));?>
						</div>
					</div>
					<div class="fields">
						<div class="field">
							<div class="label label-textarea">
										<label for="description">Description:</label>
									</div>
							<div class="textarea">
								<?php echo App::load("Helper/Html")->textareaTag("data[Admin][description]",$adminlist['description'],array("id"=>"description","class"=>"textarea"));?>
							</div>
						</div>
					</div>
					<div class="buttons">
						<input type="submit" name="submit" value="Save" />
					</div>
				</div>
			</div>
		</div>
	</div>
	<div class="box box-right">
		<div class="title">
			<h5>Acess Control Limit</h5>
		</div>
		<?php if( strtolower($adminlist['type']) != 'super'):?>
		<div class="form">
			<?php echo App::Load("Helper/Html")->checkboxTag("data[Admin][acl][]",$admin_nav_def,$adminlist['acl'],null,array('html_wrapper'=>'br'));?>
		</div>
		<?php else:?>
			<h4>Inportant</h4>
			<p>
				This is super admin has access in all tab.<br />
				<?php echo(implode(', ',$admin_nav_def)); ?>
				</p>
		<?php endif;?>
	</div>
</form>
<?php else: ?>
	<?php App::Helper('Toolbar')->setTitle("View Administrators")->setBtnDelete()->setBtnBack()->Render(array('code'=>'admin_list_view_top'));?>
    <?php if(!empty($adminlist["data"])): ?>
        <?php
            $Grid = App::Module('DataGrid');
            $Grid->setHeader(array($this->get_tag('input',array('type'=>'checkbox','id'=>'checkall','class'=>"{'mode':'Admin'}")),'#','Login Name', 'Name', 'Email','Status','Type','Options'));
			$Grid->setFooter($adminlist['paging_str']);
            foreach($adminlist["data"] as $key => $val):
                            $ctrlLinks =(strtolower($val['type'])=='super') ?
                             App::load("Helper/Html")->linkTag($this->baseurl('/admin/manage/update/' . $val['id']),App::load("Helper/Html")->imgTag($this->baseurl('/images/admin/edit.gif'),NULL,array('title'=>'Edit ','alt' => 'Edit',"class"=>"icon")),array("title"=>"Edit user information"))
                            :
                             App::load("Helper/Html")->linkTag($this->baseurl('/admin/manage/update/' . $val['id']),App::load("Helper/Html")->imgTag($this->baseurl('/images/admin/edit.gif'),NULL,array('title'=>'Edit ','alt' => 'Edit',"class"=>"icon")),array("title"=>"Edit user information"))
							 . '&nbsp;'
                            . App::load("Helper/Html")->linkTag("javascript:void(0)",App::load("Helper/Html")->imgTag($this->baseurl('/images/admin/remove.gif'),NULL,array('title'=>'Delete','alt'=>'Delete')),array('id'=>'Admin','class'=>'link_delete icon', 'title'=>'Admin_' . $val['id']));
                $Grid->addRow($this->get_tag('input',array('type'=>'checkbox','value'=>"{$val['id']}","class"=>"checkrow")),(($adminlist["page"] - 1) * $this->get_config('default_pagination') + $key + 1),$val['username'],"{$val['f_name']} {$val['l_name']}", $val['email'], $val['status'], $val['type'], $ctrlLinks);
            endforeach;
            $Grid->Render();
        ?>
    <?php else: ?>
        <?php echo $this->callElement('default/tools/message', array('caption' =>'Message','type' => 'error', 'message' => 'No Data found')); ?>
    <?php endif; ?>
	<?php App::Helper('Toolbar')->setBtnDelete()->setBtnBack()->Render(array('code'=>'admin_list_view_bottom'));?>
<?php endif; ?>